package String;

public class Point {
        private int x;
        private int y;
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    @Override
    public String toString() {
        return "Point{" +
                "x=" + x +
                ", y=" + y +
                '}';
    }

    public boolean equals(Object obj) {
        if(obj == null)return false;
        if(!(obj instanceof Point)){
            return false;
        }
        Point p = (Point) obj;
        return x == p.getX() && y == p.getY();
    }

    public static void main(String[] args) {
        Point p1 = new Point(100, 200);
        Point p2 = new Point(100, 200);
        System.out.println(p1 == p2);//false 比较地址
        //System.out.println(p1.equals(p2));
        // 重写前 false默认继承object类中的equals方法，这个方法默认就是==比较
        System.out.println(p1.equals(p2));
        //重写后 true重写equals方法，规则是自己定的
    }
}
